package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.commons.pojo.vo.PageData;
import cn.tedu.csmall.commons.security.LoginPrincipal;
import cn.tedu.csmall.commons.web.JsonResult;
import cn.tedu.csmall.product.pojo.param.SkuAddNewParam;
import cn.tedu.csmall.product.pojo.param.SkuUpdateInfoParam;
import cn.tedu.csmall.product.pojo.vo.AlbumListItemVO;
import cn.tedu.csmall.product.pojo.vo.AlbumStandardVO;
import cn.tedu.csmall.product.pojo.vo.SkuListItemVO;
import cn.tedu.csmall.product.pojo.vo.SkuStandardVO;
import cn.tedu.csmall.product.service.ISkuService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.Ignore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * csmall-server-jh
 * <p>
 * SKU的控制器类
 *
 * @author: 姜衡
 * @create: 2024-10-06 10:28
 **/

@Slf4j
@Validated
@RestController
@RequestMapping("/sku")
@Api(tags = "08. SKU模块")
public class SkuController {

    @Autowired
    private ISkuService skuService;

    // http://localhost:9180/sku/add-new
    @PostMapping("/add-new")
    @ApiOperation("新增SKU")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Valid SkuAddNewParam skuAddNewParam){
        log.debug("开始【新增SKU】的请求，参数：{}",skuAddNewParam);
        skuService.addNew(skuAddNewParam);
        return JsonResult.ok();
    }

    // http://localhost:9180/sku/{id}/delete
    @PostMapping("/{id:^\\d+$}/delete")
    @ApiOperation("根据id删除SKU")
    @ApiOperationSupport(order = 200)
    public JsonResult delete(@Range(min = 1,message = "请输入合法的ID值！")
                             @PathVariable Long id){
        log.debug("开始【根据id删除SKU】的请求，参数id：{}",id);
        skuService.delete(id);
        return JsonResult.ok();
    }

    // http://localhost:9180/sku/{id}/update
    @PostMapping("/{id:^\\d+$}/update")
    @ApiOperation("根据id修改SKU")
    @ApiOperationSupport(order = 300)
    public JsonResult update(@Range(min = 1,message = "请输入合法的ID值！")
                             @PathVariable Long id, SkuUpdateInfoParam skuUpdateInfoParam){
        log.debug("开始【根据id修改SKU】的请求，参数id：{}",id);
        skuService.update(id,skuUpdateInfoParam);
        return JsonResult.ok();
    }

    // http://localhost:9180/sku/9528
    @GetMapping("/{id:^\\d+$}")
    @ApiOperation("根据id查询SKU标准数据")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "SKU_ID", required = true, dataType = "long")
    })
    public JsonResult getAlbumStandardById(@Range(min = 1, message = "根据id查询SKU标准数据，请提交合法的ID值！")
                                           @PathVariable Long id) {
        log.debug("开始处理【根据id查询SKU标准数据】请求，ID:{}", id);
        SkuStandardVO query = skuService.getStandard(id);
        return JsonResult.ok(query);
    }

}
